package com.shinaier.laundry.snlstore.offlinecash.adapter;

import android.content.Context;
import android.graphics.Color;
import android.view.View;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.common.adapter.BaseAdapterNew;
import com.common.adapter.ViewHolder;
import com.shinaier.laundry.snlstore.R;
import com.shinaier.laundry.snlstore.network.entity.CooperativeFactoryEntity;

import java.util.List;

/**
 * Created by 张家洛 on 2018/1/11.
 */

public class ChooseCooperativeFactoryAdapter extends BaseAdapterNew<CooperativeFactoryEntity.CooperativeFactoryResult> {
    private Context context;
    private SelectFactoryListener selectFactoryListener;
    public interface SelectFactoryListener{
        void onSelectFactory(int position);
    }

    public void setSelectListener(SelectFactoryListener selectFactoryListener){
        this.selectFactoryListener = selectFactoryListener;
    }
    public ChooseCooperativeFactoryAdapter(Context context, List<CooperativeFactoryEntity.CooperativeFactoryResult> mDatas) {
        super(context, mDatas);
        this.context = context;
    }

    @Override
    protected int getResourceId(int Position) {
        return R.layout.choose_cooperative_factory_item;
    }

    @Override
    protected void setViewData(View convertView, final int position) {
        CooperativeFactoryEntity.CooperativeFactoryResult item = getItem(position);
        LinearLayout llChooseCooperativeFactoryName = ViewHolder.get(convertView,R.id.ll_choose_cooperative_factory_name);
        TextView factoryName = ViewHolder.get(convertView,R.id.factory_name);

        if (item != null){
            factoryName.setText(item.getmName());

            llChooseCooperativeFactoryName.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {
                if (selectFactoryListener != null){
                    selectFactoryListener.onSelectFactory(position);
                }
                }
            });

            if (item.isSelect){
                factoryName.setTextColor(context.getResources().getColor(R.color.red));
                llChooseCooperativeFactoryName.setBackgroundColor(Color.parseColor("#ffe9e9"));
            }else {
                factoryName.setTextColor(context.getResources().getColor(R.color.black_text));
                llChooseCooperativeFactoryName.setBackgroundColor(Color.parseColor("#f7f7f7"));
            }
        }

    }
}
